﻿@model RecurringPaymentModel

@using SmartStore.Core.Domain.Catalog;
@using Telerik.Web.Mvc.UI;

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

@Html.SmartStore().TabStrip().Name("recurringpayment-edit").Style(TabsStyle.Material).Items(x =>
{
    x.Add().Text(T("Admin.RecurringPayments.Info").Text).Content(TabInfo()).Selected(true);
    x.Add().Text(T("Admin.RecurringPayments.History").Text).Content(TabHistory());
    
    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new TabStripCreated(x, "recurringpayment-edit", this.Html, this.Model));
})

@helper TabInfo()
{        
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.InitialOrderId)
            </td>
            <td class="adminData">
				<div class="form-control-plaintext">
					@Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Order", new { id = Model.InitialOrderId }, new { })
				</div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.CustomerEmail)
            </td>
            <td class="adminData">
				<div class="form-control-plaintext">
					@Html.ActionLink(Model.CustomerEmail, "Edit", "Customer", new { id = Model.CustomerId }, new { })
				</div>
			</td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.CycleLength)
            </td>
            <td class="adminData">
				@Html.EditorFor(model => model.CycleLength)
                @Html.ValidationMessageFor(model => model.CycleLength)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.CyclePeriodId)
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.CyclePeriodId, ((RecurringProductCyclePeriod)Model.CyclePeriodId).ToSelectList())
                @Html.ValidationMessageFor(model => model.CyclePeriodId)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.TotalCycles)
            </td>
            <td class="adminData">
				@Html.EditorFor(model => model.TotalCycles)
                @Html.ValidationMessageFor(model => model.TotalCycles)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.CyclesRemaining)
            </td>
            <td class="adminData">
				<div class="form-control-plaintext">
					@Model.CyclesRemaining
				</div>
			</td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.PaymentType)
            </td>
            <td class="adminData">
				<div class="form-control-plaintext">
					@Model.PaymentType
				</div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.StartDate)
            </td>
            <td class="adminData">
				<div class="form-control-plaintext">
					@Html.DisplayFor(model => model.StartDate)
				</div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.IsActive)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.IsActive)
                @Html.ValidationMessageFor(model => model.IsActive)
            </td>
        </tr>
    </table>
}

@helper TabHistory()
{ 
   
    <table class="adminContent">
        <tr>
            <td class="pb-3">
				<div class="row">
					@if (!String.IsNullOrEmpty(Model.NextPaymentDate))
					{
						<div class="col">
							@T("Admin.RecurringPayments.History.NextPaymentDate"): <strong>@Model.NextPaymentDate</strong>
						</div>

						<div class="col-ml-auto">
							<button type="submit" name="processnextpayment" value="processnextpayment" class="btn btn-secondary">
								<span>@T("Admin.RecurringPayments.History.ProcessNextPayment")</span>
							</button>
						</div>
					}
					@if (Model.CanCancelRecurringPayment)
					{
						<div class="col col-auto pl-1">
							<button type="submit" name="cancelpayment" value="cancelpayment" class="btn btn-secondary">
								<span>@T("Admin.RecurringPayments.History.CancelPayment")</span>
							</button>
						</div>
					}
				</div>
            </td>
        </tr>

        <tr>
            <td>
                @(Html.Telerik().Grid<RecurringPaymentModel.RecurringPaymentHistoryModel>(Model.History)
                    .Name("history-grid")
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.OrderId)
                            .Width(100)
                            .Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Order", new { id = x.OrderId }, new { }))
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Order/Edit/") + "<#= OrderId #>\">" + T("Admin.Common.View").Text + "</a>");
                        columns.Bound(x => x.OrderStatus).Width(200);
                        columns.Bound(x => x.PaymentStatus).Width(200);
                        columns.Bound(x => x.ShippingStatus).Width(200);
                        columns.Bound(x => x.CreatedOn).Width(200);

                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("HistoryList", "RecurringPayment", new { recurringPaymentId = Model.Id });
                    })
                    .EnableCustomBinding(true))
            </td>
        </tr>
    </table>
}